package com.angel.web.sys;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.angel.core.util.JsonUtil;
import com.angel.core.util.Pager;
import com.angel.health.SysDict;
import com.angel.provider.sys.sysManagerDictProvider;

/**
 * 高亚林
 * 2016年9月25日下午5:46:25
 */
@Controller
@RequestMapping("/manag/dict")
public class SysManagerDictController {

	@Autowired
	private sysManagerDictProvider provider;
	
	@RequestMapping("/index")
	public String index(SysDict dict,Pager pagers,HttpServletRequest request){
		Pager pager = provider.findAll(dict, pagers);
		request.setAttribute("pager", pager);
		return "manag/dict";
	}
	
	//跳转到添加页面
	@RequestMapping("/add")
	public String add(){
		return "manag/dict_add";
	}
	
	//批量删除
	@RequestMapping("delete")
	@ResponseBody
	public String delete(String ids){
		int i = provider.delete(ids);
		return JsonUtil.toJson(i);
	}
	
	//删除单个用户
	@RequestMapping("deleteById")
	@ResponseBody
	public String deleteById(SysDict dict){
		int i = provider.deleteById(dict);
		return JsonUtil.toJson(i);
	}
	
	//保存
	@RequestMapping("/save")
	@ResponseBody
	public String save(SysDict dict,HttpServletRequest request){
		dict.setCreateBy(request.getSession().getAttribute("user").toString());
		Map<String, String> map = provider.save(dict);
		return JsonUtil.toJson(map);
	}
	
	//根据id获取数据
	@RequestMapping("/edit")
	public String edit(SysDict dict,String method,HttpServletRequest request){
		SysDict sysDict = provider.findUserById(dict);
		request.setAttribute("dict", sysDict);
		if("1".equals(method)){
			request.setAttribute("method", "1");
		}else{
			request.setAttribute("method", "2");
		}
		return "manag/dict_look";
	}
	
	//修改
	@RequestMapping("/update")
	@ResponseBody
	public String update(SysDict dict,HttpServletRequest request){
		dict.setUpdateBy(request.getSession().getAttribute("user").toString());
		Map<String, String> map = provider.update(dict);
		return JsonUtil.toJson(map);
	}
}
